﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Dao;

namespace Web.Page
{
    public partial class CS_WLLX_Query : BasePage
    {
        CS_WLLX_Dao dao = new CS_WLLX_Dao();

        protected void Page_Load(object sender, EventArgs e)
        {
            base.Page_Load(sender, e);
            if (!IsPostBack)
            {
                string vpath = Request.QueryString[WLTree.VPATH];
                if (vpath != null)
                {
                    Cache.Insert(WLTree.VPATH, vpath);
                }

                this.lbTitle.Text = "物料类型列表";
                BindGridview();
            }
        }

        protected void GridView1_PageIndexChanged(object sender, EventArgs e)
        {
            BindGridview();
        }

        protected void GridView1_PageIndexChanging(object sender, GridViewPageEventArgs e)
        {
            GridView1.PageIndex = e.NewPageIndex;
            BindGridview();
            SavePageIndex(e.NewPageIndex);
        }

        private void BindGridview()
        {
            GridView1.PageIndex = RestorePageIndex();
            List<CS_WLLX> list = dao.QueryAll();
            this.GridView1.DataSource = list;
            this.GridView1.DataBind();
        }

        protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
        {
            //if (e.Row.RowType == DataControlRowType.DataRow)
            //{
            //    ((ImageButton)(e.Row.Cells[3].Controls[0])).Attributes.Add("onclick ", "return   confirm( '确定删除？ ') ");
            //}
        }

        protected void GridView1_RowDeleting(object sender, GridViewDeleteEventArgs e)
        {
            string id = GridView1.DataKeys[e.RowIndex].Value.ToString();
            int result = dao.Delete(id);
            if (result == 1)
            {
                lbResult.Text = "删除成功";
                BindGridview();
                Cache.Insert(WLTree.LEVEL, WLTree.WL);

                ScriptManager.RegisterStartupScript(this.UpdatePanel1, this.GetType(), "onSuccess", "<script type='text/javascript'>parent.refresh('tree');</script>", false);
            }
        }

        protected void btnAdd_Click(object sender, ImageClickEventArgs e)
        {
            Response.Redirect("~/Page/CS_WLLX_Add.aspx");
        }
    }
}